import Axios from 'axios'

export const axios = Axios.create({
    baseURL: import.meta.env.VITE_BASE_API,
    headers: {
        'Content-Type': 'application/json'
    }
})
axios.interceptors.request.use(config => {
    const token = sessionStorage.getItem('token')
    if (token) {
        config.headers.Authorization = `Bearer ${token}`
    }
    return config
})


export const rq = {
    get: (url: string, params?: any) => axios.get(url, {params: params}).then(res => res.data),
    post: (url: string, data?: any) => axios.post(url, data).then(res => res.data),
    put: (url: string, data?: any) => axios.put(url, data).then(res => res.data),
    del: (url: string, params?: any) => axios.delete(url, params).then(res => res.data),
}